package com.demo.sort;

import org.junit.Before;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author Chen Jie
 * @email jie.chen@remarkdip.com
 * @date 2018/4/12.
 */
public class Main {
    private List<Person> personList;

    @Before
    public void before() {
        Person p1 = new Person("a", 10);
        Person p2 = new Person("b", 16);
        Person p3 = new Person("d", 13);
        Person p4 = new Person("c", 11);

        personList = Arrays.asList(p1, p2, p3, p4);
    }

    @Test
    public void testSort1() {
        Collections.sort(personList, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                return o1.getAge() - o2.getAge();
            }
        });

        System.out.println(personList);
    }

    @Test
    public void testSort2() {
        Collections.sort(personList, (o1, o2) -> o1.getAge() - o2.getAge());

        System.out.println(personList);
    }

    @Test
    public void testSort3() {
        personList.sort(Comparator.comparing(Person::getAge));

        System.out.println(personList);
    }
}
